package demo.IOStream;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/15-08-15-20:21
 * @Description：demo.IOStream
 */
/*
一个文件分俩半,一个线程负责第一个部分的内容,并且边读边写,另一个线程负责第二部分的内容,并 且边读边写

代码中只有俩个RandomAccessFile类型的对象 in out

in负责读 out负责写,俩个线程对象中使用是同一对随即流对象(in out),注意加锁
 */
public class AssessFile_use {
    public static void main(String[] args) {
        RandomAccessFile in = null;
        RandomAccessFile out = null;
        File file = new File("cal.txt");
        int length = (int) file.length();
        try {
            in = new RandomAccessFile("cal.txt","r");
            out = new RandomAccessFile("cal.txt","w");
            Thread thread1 = new FileThread(in,out,0,length/2);
            Thread thread2 = new FileThread(in,out,length/2,length-1);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
class FileThread extends Thread{
    RandomAccessFile in = null;
    RandomAccessFile out = null;
    int start;
    int end;

    public FileThread(RandomAccessFile in, RandomAccessFile out, int start, int end) {
        this.in = in;
        this.out = out;
        this.start = start;
        this.end = end;
    }

    @Override
    public void run() {

    }
}